package com.summer.tools.common.customize;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import lombok.EqualsAndHashCode;
import org.apache.poi.ss.usermodel.*;
import java.util.List;

/**
 * 自定义样式
 */
@EqualsAndHashCode(callSuper = false)
public class CustomerEasyExcelStyle extends AbstractVerticalCellStyleStrategy {

    private List<Integer> columnIndexes;

    public CustomerEasyExcelStyle(List<Integer> columnIndexes) {
        this.columnIndexes = columnIndexes;
    }

    @Override
    protected WriteCellStyle headCellStyle(Head head) {
        // 获取样式实例
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 获取字体实例
        WriteFont headWriteFont = new WriteFont();
        // 设置字体样式
        headWriteFont.setFontName("宋体");
        // 设置字体大小
        headWriteFont.setFontHeightInPoints((short) 11);
        // 设置字体颜色
        if (columnIndexes.contains(head.getColumnIndex())) {
            headWriteFont.setColor(IndexedColors.RED.getIndex());
        } else {
            headWriteFont.setColor(IndexedColors.BLACK.getIndex());
        }
        // 边框
        headWriteFont.setBold(false);
        // 设置表头单元格为白色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        headWriteCellStyle.setWriteFont(headWriteFont);
        return headWriteCellStyle;
    }
}
